package com.lyj.io.module.data.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.lyj.io.annotation.SysLogAnnotation;
import com.lyj.io.module.sys.entity.SysOrg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.lyj.io.module.data.entity.SysDictEntity;
import com.lyj.io.module.data.service.SysDictService;
import com.lyj.io.common.utils.PageUtils;
import com.lyj.io.common.utils.R;
import com.lyj.io.common.dto.IdsDto;

/**
 * 字典表相关api
 * @author liyaji
 * @email 17710557864@163.com
 * @date 2022-01-04 14:55:20
 */
@Api(value = "SysDictController", tags = "字典表相关api")
@RestController
@RequestMapping("/api/v1/dict")
public class SysDictController {
    @Autowired
    private SysDictService sysDictService;

    /**
     * 查询列表
     * @param
     * @return com.lyj.io.common.utils.R
     * @author: liyaji
     * @date: 2022-01-04 14:55:20
     * @exception:
     * @update:
     * @updatePerson:
     **/
    @SysLogAnnotation("查询字典列表")
    @ApiOperation(value = "查询字典列表", notes = "查询字典列表")
    @PostMapping("/getDictlist")
    public R list(@RequestBody Map<String, Object> params){
        PageUtils page = sysDictService.queryPage(params);
        return R.ok().put("page", page);
    }

    /**
     * 查询字典选项
     * @param
     * @return com.lyj.io.common.utils.R
     * @author: liyajie
     * @date: 2021/11/15 18:14
     * @exception:
     * @update:
     * @updatePerson:
     **/
    @SysLogAnnotation("查询字典选项")
    @ApiOperation(value = "查询字典选项", notes = "查询字典选项")
    @GetMapping("/getDictOptions")
    public R getDictOptions(@RequestParam Map<String, Object> params) {
        List<SysDictEntity> orgList = sysDictService.getDictOptions(String.valueOf(params.get("parentId")));
        return R.ok().put("data", orgList);
    }

    /**
     * 根据id查询
     * @param
     * @return com.lyj.io.common.utils.R
     * @author: liyaji
     * @date: 2022-01-04 14:55:20
     * @exception:
     * @update:
     * @updatePerson:
     **/
    @SysLogAnnotation("根据id查询字典")
    @ApiOperation(value = "根据id查询字典", notes = "根据id查询字典")
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		SysDictEntity sysDict = sysDictService.getById(id);
        return R.ok().put("sysDict", sysDict);
    }

    /**
     * 新增字典
     * @param
     * @return com.lyj.io.common.utils.R
     * @author: liyaji
     * @date: 2022-01-04 14:55:20
     * @exception:
     * @update:
     * @updatePerson:
     **/
    @SysLogAnnotation("新增字典")
    @ApiOperation(value = "新增字典", notes = "新增字典")
    @PostMapping("/addDict")
    public R save(@RequestBody SysDictEntity sysDict){
		sysDictService.save(sysDict);
        return R.ok();
    }

    /**
     * 更新字典
     * @param
     * @return com.lyj.io.common.utils.R
     * @author: liyaji
     * @date: 2022-01-04 14:55:20
     * @exception:
     * @update:
     * @updatePerson:
     **/
    @SysLogAnnotation("更新字典")
    @ApiOperation(value = "更新字典", notes = "更新字典")
    @PostMapping("/updateDict")
    public R update(@RequestBody SysDictEntity sysDict){
		sysDictService.updateById(sysDict);
        return R.ok();
    }

    /**
     * 删除
     * @param
     * @return com.lyj.io.common.utils.R
     * @author: liyaji
     * @date: 2022-01-04 14:55:20
     * @exception:
     * @update:
     * @updatePerson:
     **/
    @SysLogAnnotation("删除字典")
    @ApiOperation(value = "删除字典", notes = "删除字典")
    @PostMapping("/delDict")
    public R delete(@RequestBody IdsDto idsDto){
		sysDictService.removeByIds(Arrays.asList(idsDto.getIds().split(",")));
        return R.ok();
    }
}
